package com.project.collectAPI.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.collectAPI.dao.FirstclassDao;
import com.project.collectAPI.dao.SavedataDao;
import com.project.collectAPI.entity.Firstclass;
import com.project.collectAPI.entity.Savedata;
import com.project.collectAPI.service.FirstclassService;
import com.project.collectAPI.service.SavedataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * (Savedata)表服务实现类
 *
 * @author makejava
 * @since 2023-06-13 11:26:36
 */
@Service("savedataService")
public class SavedataServiceImpl extends ServiceImpl<SavedataDao, Savedata> implements SavedataService {

    SavedataService savedataService; //声明使用接口

    @Autowired
    SavedataDao savedataDao;

    @Override
    public void SaveProducts(List<Savedata> ProductDatas) {
        boolean b = savedataService.saveBatch(ProductDatas);
    }

    @Override
    public void UpdateProductById(Savedata savedata) {
        savedataDao.updateById(savedata);
    }

    @Override
    public void ClearAllProducts() {
        savedataDao.delete(null);
    }

    @Override
    public List<Savedata> getProductsDatas(String brandName) {
        List<Savedata> getList=savedataDao.selectList(new QueryWrapper<Savedata>().eq("sbrand",brandName).orderByDesc("id"));
        return !Objects.isNull(getList)?getList:null;
    }

    @Override
    public String getNearClass(String storeName) {
        Savedata oneDatas=savedataDao.getOne(storeName);
        if(!Objects.isNull(oneDatas)){
            String main=oneDatas.getFirstname();
            String sub=oneDatas.getSecondname();
            return main+":"+sub;
        }
        return null;
    }

    @Override
    public List<Savedata> getNearDatasList(String storeName,String mainName, String className, int Threshold) {
        List<Savedata> getList=savedataDao.getList(storeName,mainName,className,Threshold);
        return getList!=null?getList:null;
    }
}

